#! /bin/sh

run_test hello-world

check_output "hello-world did not work?" <<EOF
HELLO_WORLD
EOF

run_test stats

check_output "stats did not work?" <<EOF
{"ms_min":5, "ms_max":4026531840, "ms_total":123456789012345}
EOF

run_test config-file < /dev/null

check_output "empty config failed?" <<EOF
error: no config file given
EOF

run_test config-file <<EOF
Hello, World!
EOF

check_output "bogus config failed?" <<EOF
error:1:0: expecting object definition
EOF

run_test config-file <<EOF
{
  "cd_name" : "Sora",
  "cd_timeout" : 120
}
EOF

check_output "good config failed?" <<EOF
name = Sora
timeout = 120
EOF

run_test config-file <<EOF
{
  "cd_name" : "Sora",
  "cd_timeout" : 120,
}
EOF

check_output "good config failed?" <<EOF
name = Sora
timeout = 120
EOF

run_test config-file <<EOF
{
  "cd_name" : "Sora"
EOF

check_output "non-terminated config worked?" <<EOF
error:3:0: expecting ',' or '}' in object definition
EOF

run_test config-file <<EOF
{
  "cd_name" : "Sora",
  "cd_timeout" : "120",
}
EOF

check_output "number string worked?" <<EOF
error:3:16: parse error, expecting a 32-bit number
EOF

run_test config-file <<EOF
{
  cd_name : "Sora",
  "cd_timeout" : "120",
}
EOF

check_output "non-string field name worked?" <<EOF
error:2:2: expecting string for object field name
EOF

run_test config-file <<EOF
{
  "foo" : "Sora",
  "cd_timeout" : "120",
}
EOF

check_output "unknown object field worked?" <<EOF
error:2:2: unknown object field 'foo'
EOF

run_test config-file <<EOF
{
  "cd_name" = "Sora",
  "cd_timeout" : "120",
}
EOF

check_output "equal worked?" <<EOF
error:2:12: expecting ':' after object field name
EOF
